﻿var totalInstancesUsed = parseInt(localStorage.getItem('totalInstancesUsed'));
var totalCoresUsed = parseInt(localStorage.getItem('totalCoresUsed'));
var totalRAMUsed = parseInt(localStorage.getItem('totalRAMUsed'));
var totalFloatingIpsUsed = parseInt(localStorage.getItem('totalFloatingIpsUsed'));
var totalSecurityGroupsUsed = parseInt(localStorage.getItem('totalSecurityGroupsUsed'));

var maxTotalInstances = parseInt(localStorage.getItem('maxTotalInstances'));
var maxTotalCores = parseInt(localStorage.getItem('maxTotalCores'));
var maxTotalRAMSize = parseInt(localStorage.getItem('maxTotalRAMSize'));
var maxTotalFloatingIps = parseInt(localStorage.getItem('maxTotalFloatingIps'));
var maxSecurityGroups = parseInt(localStorage.getItem('maxSecurityGroups'));

var totalVolumesUsed = parseInt(localStorage.getItem('totalVolumesUsed'));
var totalGigabytesUsed = parseInt(localStorage.getItem('totalGigabytesUsed'));

var maxTotalVolumes = parseInt(localStorage.getItem('maxTotalVolumes'));
var maxTotalVolumeGigabytes = parseInt(localStorage.getItem('maxTotalVolumeGigabytes'));				
					

					
google.load('visualization', '1.0', {'packages':['corechart']});
google.setOnLoadCallback(Ins_drawChart); 
google.setOnLoadCallback(VCPUs_drawChart); 
google.setOnLoadCallback(RAM_drawChart); 
google.setOnLoadCallback(IPs_drawChart); 
google.setOnLoadCallback(Sec_drawChart); 
google.setOnLoadCallback(Vol_drawChart); 
google.setOnLoadCallback(Sto_drawChart); 
function Ins_drawChart() {
	var data = new google.visualization.DataTable();
	data.addColumn('string', 'Topping');
	data.addColumn('number', 'Slices');
	data.addRows([
		['Used', totalInstancesUsed],
		['Unused', (maxTotalInstances-totalInstancesUsed)]
	]);
	var options = {'title':'Instances',
		'width':'50%',
		'height':'50%'};		
	var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
	chart.draw(data, options);
}	
function VCPUs_drawChart() {
	var data = new google.visualization.DataTable();
	data.addColumn('string', 'Topping');
	data.addColumn('number', 'Slices');
	data.addRows([
		['Used', totalCoresUsed],
		['Unused', (maxTotalCores-totalCoresUsed)]
	]);
	var options = {'title':'VCPUs',
		'width':'50%',
		'height':'50%'};		
	var chart = new google.visualization.PieChart(document.getElementById('chart_div2'));
	chart.draw(data, options);
}	
function RAM_drawChart() {
	var data = new google.visualization.DataTable();
	data.addColumn('string', 'Topping');
	data.addColumn('number', 'Slices');
	data.addRows([
		['Used', totalRAMUsed],
		['Unused', (maxTotalRAMSize-totalRAMUsed)]
	]);
	var options = {'title':'RAM',
		'width':'50%',
		'height':'50%'};		
	var chart = new google.visualization.PieChart(document.getElementById('chart_div3'));
	chart.draw(data, options);
}
function IPs_drawChart() {
	var data = new google.visualization.DataTable();
	data.addColumn('string', 'Topping');
	data.addColumn('number', 'Slices');
	data.addRows([
		['Used', totalFloatingIpsUsed],
		['Unused', (maxTotalFloatingIps-totalFloatingIpsUsed)]
	]);
	var options = {'title':'Floating IPs',
		'width':'50%',
		'height':'50%'};			
	var chart = new google.visualization.PieChart(document.getElementById('chart_div4'));
	chart.draw(data, options);
}
function Sec_drawChart() {
	var data = new google.visualization.DataTable();
	data.addColumn('string', 'Topping');
	data.addColumn('number', 'Slices');
	data.addRows([
		['Used', totalSecurityGroupsUsed],
		['Unused', (maxSecurityGroups-totalSecurityGroupsUsed)]
	]);
	var options = {'title':'Security Groups ',
		'width':'50%',
		'height':'50%'};		
	var chart = new google.visualization.PieChart(document.getElementById('chart_div5'));
	chart.draw(data, options);
}
function Vol_drawChart() {
	var data = new google.visualization.DataTable();
	data.addColumn('string', 'Topping');
	data.addColumn('number', 'Slices');
	data.addRows([
		['Used', totalVolumesUsed],
		['Unused', (maxTotalVolumes-totalVolumesUsed)]
	]);
	var options = {'title':'Volumes',
		'width':'50%',
		'height':'50%'};			
	var chart = new google.visualization.PieChart(document.getElementById('chart_div6'));
	chart.draw(data, options);
}
function Sto_drawChart() {
	var data = new google.visualization.DataTable();
	data.addColumn('string', 'Topping');
	data.addColumn('number', 'Slices');
	data.addRows([
		['Used', totalGigabytesUsed],
		['Unused', (maxTotalVolumeGigabytes-totalGigabytesUsed)],
	]);
	var options = {'title':'Volume Storage',
		'width':'50%',
		'height':'50%'};			
	var chart = new google.visualization.PieChart(document.getElementById('chart_div7'));
	chart.draw(data, options);
	
	console.log(totalVolumesUsed + ' ' + maxTotalVolumes + ' ' + totalGigabytesUsed + ' ' + maxTotalVolumeGigabytes);	
}	


/*
var totalVolumesUsed = parseInt(localStorage.getItem('totalVolumesUsed'));
var totalGigabytesUsed = parseInt(localStorage.getItem('totalGigabytesUsed'));

var maxTotalVolumes = parseInt(localStorage.getItem('maxTotalVolumes'));
var maxTotalVolumeGigabytes = parseInt(localStorage.getItem('maxTotalVolumeGigabytes'));	
*/
